<template>
  <!--引用表格-->
  <BasicTable @register="registerTable" :rowSelection="rowSelection">
    <!--插槽:table标题-->
    <template #tableTitle>
      <a-button :disabled="selectedRowKeys?.length === 0" preIcon="ant-design:export-outlined" @click="agreebacklog"> 同意</a-button>
    </template>
  </BasicTable>
</template>

<script lang="ts" setup>
  //ts语法
  import { BasicTable, TableAction } from '/@/components/Table';
  import { useModal } from '/@/components/Modal';

  import { useMessage } from '/@/hooks/web/useMessage';
  import { removeAuthCache, setAuthCache } from '/@/utils/auth';
  import { columns, searchFormSchema } from './todo.data';
  import { list } from './todo.api';
  import { DB_DICT_DATA_KEY } from '/@/enums/cacheEnum';
  import { useUserStore } from '/@/store/modules/user';

  const { createMessage } = useMessage();
  //字典model
  const [registerModal, { openModal }] = useModal();

  import { useListPage } from '/@/hooks/system/useListPage';

  // 列表页面公共参数、方法
  const { prefixCls, tableContext } = useListPage({
    designScope: 'dict-template',
    tableProps: {
      title: '数据字典',
      api: list,
      columns: columns,
      formConfig: {
        schemas: searchFormSchema,
      },
      actionColumn: {
        width: 240,
      },
    }
  });

  //注册table数据
  const [registerTable, { reload, updateTableDataRecord }, { rowSelection, selectedRowKeys, selectedRows }] = tableContext;


  /**
   * 同意按钮事件
   */
  const agreebacklog = () => {
    createConfirm({
      iconType: 'warning',
      title: '确认操作',
      content: '是否审批选中数据?',
      onOk: async () => {
        try {
          loading.value = true;

          const data = selectedRowKey.value.map((item) => ({ agent_id: item.initiator.employee_id, task_instance_id: item.task_instance_id }));

          const response = await backlogagree(data);
          if (response.code === '000000') {
            console.log(response);
            createMessage.success('操作成功');
            handleReset();
          } else {
            message.error(response.data.message || '获取数据失败');
          }
        } catch (error) {
          message.error('获取数据出错');
        } finally {
          loading.value = false;
        }
      },
    });
  };

</script>

<style lang="less" scoped></style>
